@extends('admin.base')
@section('title', '用户列表')
@section('content')
    <div class="layui-card">
        <fieldset class="layui-elem-field">
            <div class="layui-field-box">
                <a class="layui-btn-sm" href="{{url('admin/home')}}">首页</a>&raquo;
                <span class="layui-btn-sm" href="{{url('admin/user/index')}}">用户列表</span>
            </div>
        </fieldset>
        <div class="layui-card-header" style="height:120px">
            <div>
                <span class="pull-left">
                  <div class="layui-form">
                    <div class="layui-form-item">
                      <div class="layui-inline">
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="sub_keywords" name="keywords"
                                   value="{{ isset($keywords) ? $keywords : '' }}" placeholder="请输入昵称">
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="sub_phone" name="sub_phone"
                                 value="{{ isset($sub_phone) ? $sub_phone : '' }}" placeholder="请输入手机号">
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="sub_email" name="sub_email"
                                   value="{{ isset($sub_email) ? $sub_email : '' }}" placeholder="请输入邮箱">
                        </div>
                        <label class="layui-form-label" style="width:120px">云仓库状态</label>
                        <div class="layui-input-inline">
                            <select name="sub_state" lay-verify="required">
                                <option value="0">请选择</option>
                                <option value="1" @if($sub_state == 1) selected @endif>开启</option>
                                <option value="2" @if($sub_state == 2) selected @endif>关闭</option>
                            </select>
                        </div>
                        <label class="layui-form-label" style="width:120px">用户状态</label>
                        <div class="layui-input-inline">
                            <select name="sub_status" lay-verify="required">
                                <option value="0">请选择</option>
                                <option value="1" @if($sub_status == 1) selected @endif>启用</option>
                                <option value="2" @if($sub_status == 2) selected @endif>禁用</option>
                            </select>
                        </div>
                        <label class="layui-form-label">时间</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" class="jeinput" id="test11" placeholder="创建时间(年月日~年月日)"
                                   name="month" value="{{ isset($month) ? $month : '' }}" readonly>
                        </div>

                      </div>
                        <div  class="layui-form-item">
                            <div class="layui-input-inline">
                            <button class="layui-btn" lay-submit lay-filter="selectsub" style="margin-bottom:10px">搜索</button>
                            {{--<button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit lay-filter="exportsub" ></i>导出</button>--}}
                        </div>
                        </div>
                    </div>
                  </div>
                </span>
            </div>
        </div>

        <div class="layui-card-body">
            <style>
                table tr td.tc, table tr th.tc {
                    text-align: center;
                    cursor: default;
                }
            </style>
            <table class="layui-table" lay-even lay-size="">
                <colgroup>
                    <col width="">
                    <col width="">
                    <col width="">
                    <col width="">
                    <col width="">
                    <col width="">
                </colgroup>
                <thead>
                <tr>
                    <th class="tc">ID</th>
                    <th class="tc">昵称</th>
                    <th class="tc">上级账号</th>
                    <th class="tc">手机号</th>
                    <th class="tc">邮箱</th>
                    <th class="tc">现金</th>
                    <th class="tc">货款</th>
                    <th class="tc">邀请码</th>
                    <th class="tc">级别</th>
                    <th class="tc">是否实名</th>
                    <th class="tc">云库存开启状态</th>
                    <th class="tc">状态</th>
                    <th class="tc">创建时间</th>
                </tr>
                <tbody>
                @if($list->isEmpty())
                    <tr>
                        <td colspan="11" class="tc">暂无数据</td>
                    </tr>
                @else
                    @foreach ($list as $v)
                        <tr>
                            <td class="tc">{{ $v->id }}</td>
                            <td class="tc">{{ $v['user'] }}</td>
                            <td class="tc">{{ $v['puser'] }}</td>
                            <td class="tc">{{ $v['phone'] }}</td>
                            <td class="tc">{{ $v['email'] }}</td>
                            <td class="tc">{{ $v['money'] }}</td>
                            <td class="tc">{{ $v['lock_money'] }}</td>
                            <td class="tc">{{ $v['invite_code'] }}</td>
                            <td class="tc">{{ $v['level_name'] }}</td>
                            <td class="tc">@if($v['is_auth'] == 1)<span style='color:green;cursor:pointer' onclick="layer_cy('{{$v['true_name']}}','{{$v['id_card']}}')">已实名</span>@else未实名@endif</td>
                            <td class="tc">@if($v['is_vip'] ==1)开启@else关闭@endif</td>

                            <td class="tc">
                                <form class="layui-form " action="">
                                    <input type="checkbox" @if($v['state']==1) checked @endif name="" lay-skin="switch"
                                           lay-filter="switchTest" lay-text="启用|禁用" value="{{ $v['id'] }}">
                                </form>
                            </td>
                            <td class="tc">{{$v['created_at']}}</td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
                </thead>
            </table>
            <!-- 分页 -->
            <div class="sabrosus">{{ $list->appends(['keywords'=>$keywords,'sub_phone'=>$sub_phone,'sub_email'=>$sub_email,'sub_state'=>$sub_state,'sub_status'=>$sub_status,'month'=>$month])->links() }}</div>
        </div>
        <div id='content' style="margin-top:10px;display:none">
            <div class="layui-form-item">
                <label class="layui-form-label" style="width:120px">姓名</label>
                <div class="layui-input-inline">      
                <input type="text" name="name" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" value='' readonly class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width:120px">身份证号</label>
                <div class="layui-input-inline">      
                <input type="text" name="idcard" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" value='' readonly class="layui-input">
                </div>
            </div>
        </div>

    </div>
@endsection
@section('js')
    <script>
        layui.use('form', function () {
            var form = layui.form;

            //搜索
            form.on('submit(selectsub)', function (data) {
                let keywords = $('#sub_keywords').val();//关键字
                let month = $("#test11").val();//时间
                var sub_phone = $("#sub_phone").val();//搜索手机号
                var sub_email = $("#sub_email").val();//搜索邮箱
                var sub_state = $("select[name=sub_state]").val();//搜索云仓库状态
                var sub_status = $("select[name=sub_status]").val();//搜索用户状态
                var page = $("input[name=page]").val();//搜索分页
                location.href = "{{url('admin/user/index')}}" + "?keywords=" + keywords + "&month=" + month + '&page=' + page + '&sub_phone=' + sub_phone + '&sub_email=' + sub_email+'&sub_state='+sub_state+'&sub_status='+sub_status;
                return false;
            });

            //监听指定开关
            form.on('switch(switchTest)', function (data) {
                var id = data.value;

                if (data.elem.checked) {
                    var state = 1;//启用
                } else {
                    var state = 2;//禁用               
                }
                ajax('/admin/user/up_state', {id: id, state: state});
            });
            
        });

        function layer_cy(name,idcard){
            $("input[name=name]").val(name);
            $("input[name=idcard]").val(idcard);
            layui.use('layer', function(){
                var layer = layui.layer;
                layer.open({
                    type: 1,
                    title: '用户实名信息',
                    area:['600px','300px'],
                    content: $('#content'), //这里content是一个普通的String
                });
            });
        }
    </script>
@endsection